home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / gdevegaa.asm < prev    next >
Encoding:
Assembly Source File  |  2001-01-01  |  6.6 KB  |  279 lines

  1. ;    Copyright (C) 1989, 1992 Aladdin Enterprises.  All rights reserved.
  2. ; This file is part of AFPL Ghostscript.
  3. ; AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  4. ; distributor accepts any responsibility for the consequences of using it, or
  5. ; for whether it serves any particular purpose or works at all, unless he or
  6. ; she says so in writing.  Refer to the Aladdin Free Public License (the
  7. ; "License") for full details.
  8. ; Every copy of AFPL Ghostscript must include a copy of the License, normally
  9. ; in a plain ASCII text file named PUBLIC.  The License grants you the right
  10. ; to copy, modify and redistribute AFPL Ghostscript, but only under certain
  11. ; conditions described in the License.  Among other things, the License
  12. ; requires that the copyright notice and this notice be preserved on all
  13. ; copies.
  14.  
  15. ; $Id: gdevegaa.asm,v 1.2 2000/09/19 19:00:12 lpd Exp $
  16. ; gdevegaasm.asm
  17. ; Assembly code for Ghostscript PC frame buffer driver
  18.  
  19. gdevegaasm_TEXT    SEGMENT    BYTE PUBLIC 'CODE'
  20.     ASSUME    CS:gdevegaasm_TEXT
  21.  
  22. ; Note: Turbo C uses si and di for register variables, so
  23. ; we have to preserve them.
  24.  
  25. ; Normal entry and exit.  Arguments are relative to bp.
  26. enterp    macro
  27.     push    bp
  28.     mov    bp,sp
  29.     x = 6                ; offset of arguments,
  30.                     ; large code model
  31.     endm
  32. leavep    macro
  33.     pop    bp
  34.     endm
  35. ; Fast entry and exit, for procedures that don't use bx until
  36. ; they've fetched all their arguments.  Arguments are relative to ss:bx.
  37. enterf    macro
  38.     mov    bx,sp
  39.     x = 4                ; offset of arguments,
  40.                     ; large code model
  41.     endm
  42. leavef    macro
  43.     endm
  44.  
  45. ; Fast call to VESA set-page routine.
  46. ; void vesa_call_set_page(void (*set_page_proc)(int), int page_no, int win_no)
  47.     PUBLIC    _vesa_call_set_page
  48. _vesa_call_set_page proc far
  49.     enterf
  50.     mov ax,4f05h
  51.     mov dx,ss:[bx+x+4]            ; page_no
  52.     push ss:[bx+x+2]            ; set_page_proc
  53.     push ss:[bx+x]
  54.     mov bx,ss:[bx+x+6]            ; win_no
  55.     ret
  56. _vesa_call_set_page endp
  57.  
  58. ; Structure for operation parameters.
  59. ; Note that this structure is shared with C code.
  60. ; Not all parameters are used for every operation.
  61. ; typedef struct rop_params_s {
  62. p_dest    equ    0    ; fb_ptr dest;    /* pointer to frame buffer */
  63. p_draster equ    4    ; int draster;    /* raster of frame buffer */
  64. p_src    equ    6    ; const byte far *src; /* pointer to source data */
  65. p_sraster equ    10    ; int sraster;    /* source raster */
  66. p_width    equ    12    ; int width;    /* width in bytes */
  67. p_height equ    14    ; int height;    /* height in scan lines */
  68. p_shift equ    16    ; int shift;    /* amount to right shift source */
  69. p_invert equ    18    ; int invert;    /* 0 or -1 to invert source */
  70. p_data    equ    20    ; int data;    /* data for fill */
  71. ; } rop_params;
  72.  
  73. ; void memsetcol(rop_params _ss *rop)
  74. ; {    byte far *addr = rop->dest;
  75. ;    int yc = rop->height;
  76. ;    while ( yc-- )
  77. ;     { byte discard = *addr;
  78. ;       *addr = rop->data;
  79. ;       addr += rop->draster;
  80. ;     }
  81. ; }
  82.     PUBLIC    _memsetcol
  83. _memsetcol proc    far
  84.     enterf
  85.     push    ds
  86.     mov    ax,ss
  87.     mov    ds,ax
  88.     mov    bx,[bx+x]            ; rop
  89.     mov    cx,[bx].p_height
  90.     jcxz    msc0                ; height == 0
  91.     mov    ax,[bx].p_data
  92.     mov    dx,[bx].p_draster
  93.     lds    bx,[bx].p_dest
  94. ; Unroll the loop -- two copies.
  95.     inc    cx        ;round up to nearest word.  cx>=2 now.
  96.     shr    cx,1        ;make byte count into word count.
  97.     jnc    msc2        ;if it had been odd, do a half word first.
  98. msc1:    mov    ah,[bx]
  99.     mov    [bx],al
  100.     add    bx,dx
  101. msc2:    mov    ah,[bx]
  102.     mov    [bx],al
  103.     add    bx,dx
  104.     loop    msc1
  105.     pop    ds
  106. msc0:    leavef
  107.     ret
  108. _memsetcol ENDP
  109.  
  110. ; void memsetrect(rop_params _ss *rop)
  111. ; {    byte far *addr = rop->dest;
  112. ;    int yc = rop->height;
  113. ;    while ( yc-- )
  114. ;     { int cnt = rop->width;
  115. ;       while ( cnt-- ) *addr++ = rop->data;
  116. ;       addr += rop->drast - rop->width;
  117. ;     }
  118. ; }
  119.     PUBLIC    _memsetrect
  120. _memsetrect proc    far
  121.     enterf
  122.     push    ds
  123.     mov    ax,ss
  124.     mov    ds,ax
  125.     mov    bx,[bx+x]            ; rop
  126.     mov    cx,[bx].p_height
  127.     jcxz    msr0                ; height == 0
  128.     push    si
  129.     push    di
  130.     mov    ax,[bx].p_data
  131.     les    di,[bx].p_dest
  132.     cld
  133.     mov    dx,[bx].p_draster
  134.     mov    si,cx                ; si = height
  135.     mov    cx,[bx].p_width
  136.     sub    dx,cx
  137.     cmp    cx,10
  138.     ja    msrl                ; large count, use fast loop
  139. ; Small count, rep stosb is faster.
  140. msrs:    mov    cx,[bx].p_width
  141.     rep    stosb
  142.     add    di,dx
  143.     dec    si                ; count reps
  144.     jnz    msrs
  145.     pop    di
  146.     pop    si
  147. msr0:    pop    ds
  148.     leavef
  149.     ret
  150. ; Large count, loop by words rather than bytes.
  151. msrl:    mov    ah,al            ;we may be storing words...
  152. msr1:    mov    cx,[bx].p_width
  153.     test    di,1            ;test for an even address
  154.     je    msr2            ;if even, we can store words.
  155.     stosb                ;otherwise we need to even it out.
  156.     dec    cx            ;(cx is at least one here)
  157. msr2:    shr    cx,1            ;convert byte count into word count
  158.     rep    stosw            ;store them puppies as fast as we can.
  159.     jnc    msr3            ;if an odd number, store it, too.
  160.     stosb                ;(no need to dec cx here).
  161. msr3:    add    di,dx
  162.     dec    si            ; count reps
  163.     jnz    msr1
  164.     pop    di
  165.     pop    si
  166.     pop    ds
  167.     leavef
  168.     ret
  169. _memsetrect ENDP
  170.  
  171. ; void memrwcol(rop_params _ss *rop)
  172. ; {    byte far *dp = rop->dest;
  173. ;    const byte far *sp = rop->src;
  174. ;    int yc = rop->height;
  175. ;    int shift = rop->shift;
  176. ;    while ( yc-- )
  177. ;     { byte discard = *dp;
  178. ;       *dp = ((*sp >> shift) + (*sp << (8 - shift))) ^ rop->invert;
  179. ;       dp += rop->draster, sp += rop->sraster;
  180. ;     }
  181. ; }
  182.     PUBLIC    _memrwcol
  183. _memrwcol proc far
  184.     enterp
  185.     push    ds
  186.     mov    ax,ss
  187.     mov    ds,ax
  188.     mov    bx,[bp+x]            ; rop
  189.     cmp    word ptr [bx].p_height,0
  190.     jz    short mrw0
  191.     push    si
  192.     push    di
  193. ; Register usage:
  194. ;   ds:si = sp, es:di = dp, bx = sraster, dx = draster, cl = shift,
  195. ;   ch = invert, ah = low byte of yc.
  196.     push    [bx].p_height
  197.     mov    dx,[bx].p_draster
  198.     mov    ax,[bx].p_sraster
  199.     mov    cl,[bx].p_shift
  200.     mov    ch,[bx].p_invert
  201.     les    di,[bx].p_dest
  202.     lds    si,[bx].p_src
  203.     mov    bx,ax
  204.     mov    ah,[bp-8]            ; low byte of yc
  205.     test    ah,ah
  206.     jz    mrw2
  207. mrw1:    mov    al,[si]
  208.     ror    al,cl
  209.     xor    al,ch
  210.     xchg    es:[di],al
  211.     add    si,bx
  212.     add    di,dx
  213.     dec    ah
  214.     jnz    mrw1
  215. mrw2:    dec    byte ptr [bp-7]            ; high byte of yc
  216.     jge    mrw1
  217.     add    sp,2                ; pop yc
  218.     pop    di
  219.     pop    si
  220. mrw0:    pop    ds
  221.     leavep
  222.     ret
  223. _memrwcol ENDP
  224.  
  225. ; void memrwcol2(rop_params _ss *rop)
  226. ; {    byte far *dp = rop->dest;
  227. ;    const byte far *sp = rop->src;
  228. ;    int yc = rop->height;
  229. ;    int shift = rop->shift;
  230. ;    while ( yc-- )
  231. ;     { byte discard = *dp;
  232. ;       *dp = ((sp[1] >> shift) + (*sp << (8 - shift))) ^ rop->invert;
  233. ;       dp += rop->draster, sp += rop->sraster;
  234. ;     }
  235. ; }
  236.     PUBLIC    _memrwcol2
  237. _memrwcol2 proc far
  238.     enterp
  239.     push    ds
  240.     mov    ax,ss
  241.     mov    ds,ax
  242.     mov    bx,[bp+x]            ; rop
  243.     cmp    word ptr [bx].p_height,0
  244.     jz    short mrw20
  245.     push    si
  246.     push    di
  247. ; Register usage:
  248. ;   ds:si = sp, es:di = dp, bx = sraster, dx = draster, cl = shift,
  249. ;   ch = invert.
  250.     push    [bx].p_height
  251.     mov    dx,[bx].p_draster
  252.     mov    ax,[bx].p_sraster
  253.     mov    cl,[bx].p_shift
  254.     mov    ch,[bx].p_invert
  255.     les    di,[bx].p_dest
  256.     lds    si,[bx].p_src
  257.     mov    bx,ax
  258. mrw21:    mov    ax,[si]                ; bytes are in wrong order...
  259.     ror    ax,cl
  260.     xor    ah,ch                ; ... so result is in ah
  261.     xchg    es:[di],ah
  262.     add    si,bx
  263.     add    di,dx
  264.     dec    word ptr [bp-8]            ; yc
  265.     jg    mrw21
  266.     add    sp,2                ; pop yc
  267.     pop    di
  268.     pop    si
  269. mrw20:    pop    ds
  270.     leavep
  271.     ret
  272. _memrwcol2 ENDP
  273.  
  274. gdevegaasm_TEXT    ENDS
  275.     END
  276.